function f = gen_eomdate(year_start , year_end , month_start , month_end)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function generates end-of-month dates for a given starting year and
% ending year.
%
% INPUT:
%   year_start  - starting year
%   year_end    - ending year
%   month_start - starting month [optional]. Default 1
%   month_end   - ending month [optional]. Default 12
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Check input
if nargin < 2
    error('2 inputs required!')
end

switch nargin
    case 2
        month_start = 1;
        month_end = 12;
    case 3
        if month_start < 1 || month_start > 12
            error('Wrong starting month!')
        end
        
        month_end = 12;
    case 4
        if month_start < 1 || month_start > 12
            error('Wrong starting month!')
        end
        if month_end < 1 || month_end > 12
            error('Wrong ending month!')
        end
end


%% Generate dates

f_raw = eomdate(kron( (year_start : year_end)' , ones(12 , 1)) , ...
            kron( ones(year_end - year_start + 1 , 1) , (1 : 12)') , 'datetime');
        
f = f_raw(month_start : end - 12 + month_end);
end